package controller;

import entity.Dept;
import service.DeptService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.Objects;

@WebServlet("/dept/*")
public class DeptServlet extends BaseServlet{

    private DeptService deptService = new DeptService();


    /**
     *查询所有部门
     * @param req
     * @param resp
     * @throws ServletException
     * @throws IOException
     */
    protected void findAllDept(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        List<Map<String, Object>> deptMapList = deptService.findAllDept();

        req.setAttribute("deptMapList", deptMapList);
        req.getRequestDispatcher("/html/department.jsp").forward(req, resp);

    }


    protected void findAll(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        List<Dept> deptList =deptService.findAll();

        writerObjToString(resp, deptList);
    }
}
